/*--
 * RegistryUtils.cs: Generically useful registry manipulation methods.
 *--
 * For more information, please visit the Registrar Project site:
 *   http://code.google.com/p/registrar/
 *--
 * (c) 2006 Christopher E. Granade.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; exactly version 2
 * of the License applies to this software.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

using Microsoft.Win32;

using System;

namespace Registrar {
	
	public static class RegistryUtils {
		
		// Given a registry key and two paths under it,
		// copies from one to the other.
		public static void CopyKey(RegistryKey rk, string from, string to) {
			
			// make the new key and open the old one.
			RegistryKey newkey = rk.CreateSubKey(to),
			            oldkey = rk.CreateSubKey(from);
			
			// deal with the values first.
			foreach (string vn in oldkey.GetValueNames()) {
				
				object o = oldkey.GetValue(vn);
				if (o == null) o = "";
				newkey.SetValue(vn, o);
				
			}
			
			// Now for the subkeys.
			foreach (string kn in oldkey.GetSubKeyNames()) {
			
				CopyKey(rk, from + '\\' + kn, to + '\\' + kn);
			
			}
			
		}
		
		public static void MoveKey(RegistryKey rk, string from, string to) {
			
			CopyKey(rk, from, to);
			rk.DeleteSubKeyTree(from);
			
		}
		
	}
	
}
